<?php
/*
 * @Author: 李明
 * @Date: 2022-01-13 10:58:19
 * @LastEditTime: 2022-02-20 12:29:46
 * @LastEditors: 李明
 * @Description:
 * @FilePath: /CRM2.0-PHP/app/Http/Resources/Order/InterestOrder.php
 * @山东壹零贰肆信息科技有限公司
 */

namespace App\Http\Resources\Order;

use Illuminate\Http\Resources\Json\JsonResource;

use function Ramsey\Uuid\v1;

class InterestOrder extends JsonResource
{
    /**
     * Transform the resource into an array.
     *
     * @param  \Illuminate\Http\Request  $request
     * @return array|\Illuminate\Contracts\Support\Arrayable|\JsonSerializable
     */
    public function toArray($request)
    {
        $data['id'] = $this->id;
        $data['contract_no'] = $this->order->contract_no; // 合同编号
        $data['order_money'] = $this->order->order_money; // 合同金额
        $data['valid_time'] =  date('Y-m-d', strtotime($this->order->valid_time)); // 生效日期
        $data['contract_end_date'] =  date('Y-m-d', strtotime($this->order->contract_end_date)); // 到期日期
        $data['product_name'] = $this->order->product->name; // 产品名称
        switch ($this->order->product->time_unit) {
            case '1':
                $time_unit = '日';
                break;
            case '2':
                $time_unit = '月';
                break;
            case '3':
                $time_unit = '年';
                break;
            default:
                $time_unit = '出现问题';
                break;
        }
        $data['product_long_time'] = $this->order->product->long_time . $time_unit; // 投资期限
        $data['date'] = date('Y-m-d', strtotime($this->date)); // 当前还款日期
        // $data['next_date'] = date('Y-m-d', strtotime($this->next_date)); // 下期还款日期
        $data['interest'] = $this->interest; // 本期应还利息
        $data['money'] = $this->money; // 本金
        $data['type'] = $this->type; // 2为正常期 3为最后一期
        $data['is_exit'] = $this->is_exit; //是否提起终止
        $data['num'] = $this->num; //第几期
        $data['num_all'] = $this->num_all; //共多少期
        $data['interest_money'] = $this->interest_money; //实际打款金额
        $data['payment_amount_round'] = round($this->payment_amount, 2); // 应付打款金额
        $data['real_time'] = date('Y-m-d', strtotime($this->real_time)); // 实际打款时间
        if ($data['real_time'] == '1970-01-01') {
            $data['real_time']  = '暂未付款';
        }
        $data['update_time'] =  date('Y-m-d', strtotime($this->update_time)); // 更新时间
        $data['user_name'] = $this->order->user->name; // 用户名称
        $data['id_number'] = $this->order->user->id_number; // 用户身份证号
        $data['worker_name'] = $this->order->worker->name; // 客户经理名称
        $data['account_name'] = $this->order->bank_card->account_name; // 开户名称
        $data['open_name'] = $this->order->bank_card->bank_sum_name; // 开户行
        $data['bank_num'] = $this->order->bank_card->bank_num; // 银行卡号
        $data['bank_name'] = $this->order->bank_card->bank->bank_name; // 开户名称
        $data['interest_round'] = round($this->interest, 0);
        // $data['payment_amount'] = $this->money + $this->interest;
        $data['status'] = $this->status;
        $bank_card_status = $this->order->bank_card->status;
        if ($bank_card_status == 1) {
            $data['bank_card_status'] = '未认证';
        } elseif ($bank_card_status == 2) {
            $data['bank_card_status'] = '认证中';
        } elseif ($bank_card_status == 3) {
            $data['bank_card_status'] = '已认证';
        } else {
            $data['bank_card_status'] = '未知';
        }
        $receivable_type = $this->receivable_type;
        if ($receivable_type == 2) {
            $data['receivable_type'] = '线上回款';
        } elseif ($receivable_type == 1) {
            $data['receivable_type'] = '普通回款';
        } else {
            if ($this->status == 3 || $this->status == 2) {
                $data['receivable_type'] = '普通回款';
            } else {
                $data['receivable_type'] = '暂未回款';
            }
        }

        return $data;
    }
}
